package com.xyzwps.server.paimon.ui.graphql

import com.xyzwps.server.paimon.app.RegisterAppService
import com.xyzwps.server.paimon.app.*
import com.xyzwps.server.paimon.app.dto.ArticleCreateInput
import com.xyzwps.server.paimon.app.dto.ArticleUpdateInput
import com.xyzwps.server.paimon.app.dto.LoginInput
import com.xyzwps.server.paimon.app.dto.LoginSendVcodeInput
import com.xyzwps.server.paimon.app.dto.Me
import com.xyzwps.server.paimon.app.dto.MeUpdateInput
import com.xyzwps.server.paimon.app.dto.RegisterInput
import com.xyzwps.server.paimon.app.dto.RegisterSendVcodeInput
import com.xyzwps.server.paimon.spring.AuthUser
import org.springframework.graphql.data.method.annotation.Argument
import org.springframework.graphql.data.method.annotation.MutationMapping
import org.springframework.stereotype.Controller

@Controller
class Mutations(
    private val articleAppService: ArticleAppService,
    private val loginAppService: LoginAppService,
    private val registerAppService: RegisterAppService,
    private val meAppService: MeAppService
) {

    @MutationMapping
    fun articleCreate(@Argument input: ArticleCreateInput, @AuthUser user: ContextUser): String {
        return articleAppService.create(user, input)
    }

    @MutationMapping
    fun articleUpdate(
        @Argument uid: String,
        @Argument input: ArticleUpdateInput,
        @AuthUser user: ContextUser,
    ): String {
        return articleAppService.update(user, uid, input)
    }

    @MutationMapping
    fun loginSendVcode(@Argument input: LoginSendVcodeInput): String {
        return loginAppService.sendVcode(input)
    }

    @MutationMapping
    fun login(@Argument input: LoginInput): Me {
        return loginAppService.login(input)
    }

    @MutationMapping
    fun meUpdate(@Argument input: MeUpdateInput, @AuthUser user: ContextUser): Me {
        return meAppService.meUpdate(user, input)
    }

    @MutationMapping
    fun registerSendVcode(@Argument input: RegisterSendVcodeInput): String {
        return registerAppService.sendRegisterVcode(input)
    }

    @MutationMapping
    fun register(@Argument input: RegisterInput): String? {
        registerAppService.register(input)
        return null
    }
}
